<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>用户信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <script src="js/jquery-3.6.0.min.js"></script>

    <script>
        function deleteUser(obj, index, id) {
            // 数据库删除
            $.get({
                url: "rbsystemUser/delete?id=" + id,
                dataType: 'JSON',
                //请求成功
                success: function (data) {
                    if (data.code === 0) {
                        layer.alert("删除成功！");
                        obj.del();
                        layer.close(index);
                    } else {
                        layer.alert("请求删除失败！");
                    }
                },
                error: function () {
                    layer.alert("请求出错！");
                }
            })
        }
    </script>

    <script src="layui/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['table', 'laypage'], function () {
            var table = layui.table;
            var laypage = layui.laypage;

            table.render({
                elem: '#test',
                url: 'rbsystemUser/selectPage',
                height: 810,
                toolbar: '#toolbarDemo',
                title: '用户数据表',
                totalRow: true,
                cols: [
                    [{
                        type: 'checkbox',
                        fixed: 'left'
                    }, {
                        field: 'userId',
                        hide: true
                    }, {
                        field: 'userPwd',
                        hide: true
                    }, {
                        field: 'userName',
                        title: '用户名',
                        width: 150,
                        fixed: 'left',
                        unresize: true,
                        sort: true,
                        totalRowText: '合计'
                    }, {
                        field: 'userSex',
                        title: '性别',
                        sort: true,
                        width: 200
                    }, {
                        field: 'userMobile',
                        title: '联系电话',
                        width: 200
                    }, {title: '操作', toolbar: '#barDemo', width: 220}]
                ],
                page: { //支持传入 laypage 组件的所有参数
                    layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'] //自定义分页布局
                    , groups: 5 //显示 5 个连续页码
                    , first: "首页" //不显示首页
                    , last: "尾页" //不显示尾页
                    , limit: 20
                    , limits: [5, 10, 20, 50, 100]
                }
            });
            //完整功能,跳转
            laypage.render({
                elem: 'Demo7' //分页容器的id
                ,
                skin: '#1E9FFF' //自定义选中色值
                ,
                skip: true //开启跳页
                ,
                jump: function (obj, first) {
                    if (!first) {
                        layer.msg('第' + obj.curr + '页', {
                            offset: 'b'
                        });
                    }
                }
            });
            //工具栏事件
            table.on('toolbar(test)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'addData':
                        // 跳转添加界面
                        window.top.changeIframe('user_add');
                        break;
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                        break;
                }
            });
            //监听工具条
            table.on('tool(test)', function (obj) {
                // 表单数据
                var data = obj.data;
                var id = data.userId;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        deleteUser(obj, index, id);
                    });
                } else if (obj.event === 'edit') {
                    /* 暂存session，跳转编辑页面 */
                    window.sessionStorage.setItem('user', JSON.stringify(data))
                    window.top.changeIframe('user_update');
                } else if (obj.event === 'detail') {
                    layer.msg('ID：' + id + ' 的查看操作');
                }
            });

        });
    </script>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="addData">新建车次</button>
            <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        </div>
    </script>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

</head>
<body>
<table class="layui-hide" id="test" lay-filter="test"></table>
</body>
</html>
